#include "Head.h"

extern string filename;
FP_Tree::FP_Tree()
{
	count=0;
	first=next=NULL;
}

FP_Tree::~FP_Tree()
{
};

void FP_Tree::DestroyTree(FP_Tree * Point)
{
	if(Point)
	{
		if(Point->first)
			DestroyTree(Point->first);
		if(Point->next)
			DestroyTree(Point->next);
	}

	delete Point;
	Point=NULL;
}

FP_Tree * FP_Tree::CreateTree(FP_Tree * point)
{
	vector<string> item=File(filename);
	map<string,int> temp_item1=A->Candidate_item1(item);
	map<string,int> Temp;
	vector<string> sorted_temp_item;
	vector<Pair> Sorted_Temp_item1(temp_item1.begin(),temp_item1.end());

	sort(Sorted_Temp_item1.begin(),Sorted_Temp_item1.end(),CmpByValue());
	int i=1;
	
	for(auto iter=Sorted_Temp_item1.begin();iter!=Sorted_Temp_item1.end();iter++)
	{
		sorted_temp_item.push_back(iter->first);
	}
	string s;
	string word;
	string separate(" ,\t:\v\r\n\f");                    
	string ::size_type startpos=0,endpos=0;
	ifstream in(filename);
	vector<string> Item;
	map<string,int>File_Item;
	if(!in.is_open())
		exit(1);
	while(!in.eof())
	{
		File_Item.clear();
		Item.clear();
		getline(in,s);
		s=s+"\n";
		while ((startpos=s.find_first_not_of(separate,endpos))!=string::npos)
		{
			endpos=s.find_first_of(separate,startpos);
			word.assign(s.begin()+startpos,s.begin()+endpos);
			Item.push_back(word);
		}
		endpos=0;
		s.clear();
		vector<string> temp;
		for(auto iter=Item.begin();iter!=Item.end();iter++)
		{
			int j=1;
			for(auto iter1=sorted_temp_item.begin();iter1!=sorted_temp_item.end();iter1++)
			{
				if(*iter==*iter1)
					File_Item[*iter]=j;
				j++;
			}

		}

		FP_Tree * root=new FP_Tree;

	}

	

	in.close();

	return NULL;
}

FP_Tree * FP_Tree::Point(FP_Tree *T,string value)
{
	queue<FP_Tree*> Queue;

	if(T)
	{
		Queue.push(T);
		while (!Queue.empty())
		{
			FP_Tree * New=Queue.front();
			Queue.pop();
			if(New->value==value)
				return New;
			if(New->first)
				Queue.push(New->first);
			if(New->next)
				Queue.push(New->next);
		}
	}

	


	return NULL;

}

